//
//  QualificIntroTableCell.m
//  ATMCash
//
//  Created by zhengchengfeng on 2024/9/8.
//

#import "QualificIntroTableCell.h"

@implementation QualificIntroTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        self.backV = [[UIView alloc] init];
        self.backV.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.backV];
        [self.backV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(10);
            make.top.equalTo(self.contentView.mas_top);
            make.bottom.equalTo(self.contentView.mas_bottom);
            make.right.equalTo(self.contentView.mas_right).offset(-10);
        }];
        self.backV.layer.cornerRadius = 10;
        self.backV.layer.masksToBounds = YES;
        
        self.iconV = [[UIImageView alloc] init];
        [self.backV addSubview:self.iconV];
        [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.backV.mas_top).offset(20);
            make.width.with.height.equalTo(@80);
//            make.centerX.equalTo(self.backV).multipliedBy(0.5).offset(-40);
            make.left.equalTo(self.backV.mas_left).offset((kScreenWidth - 20 - 80)/2);
        }];
        
        self.lab = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:16] color: RGB(7, 44, 9)];
        [self.backV addSubview:self.lab];
        self.lab.textAlignment = 1;
        self.lab.numberOfLines = 0;
        [self.lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.backV.mas_left).offset(20);
            make.right.equalTo(self.backV.mas_right).offset(-20);
            make.top.equalTo(self.iconV.mas_bottom).offset(10);
            make.bottom.equalTo(self.backV.mas_bottom).offset(-15);
        }];
        
        
    }
    return self;
}

- (void)setModel:(QualificaIntroModel *)model{
    _model = model;
    self.iconV.image = [UIImage imageNamed:model.iconName];
    self.lab.attributedText = [StringUtil setText:esString(model.title) lineSpacing:4 font:[UIFont fontWithName:kFuturaMedium size:16] withAlignment:1];
}

+ (CGFloat)getCellHeight:(QualificaIntroModel *)mm{
    CGFloat hh = 120 + 5;
    
    NSString *str = esString(mm.title);
    
//    CGRect rec = [str boundingRectWithSize:CGSizeMake(kScreenWidth - 40, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:kFuturaMedium size:14]} context:nil];
    
    CGSize size = [StringUtil textSizeWithText:str font:[UIFont fontWithName:kFuturaMedium size:16] numberOfLines:0 lineSpacing:5 constrainedWidth:kScreenWidth - 60];
    
    return hh + size.height;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
